home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / X11R4 / cmds / X / ddx / cfb / cfbgetsp.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-02-15  |  4.7 KB  |  166 lines

  1. /***********************************************************
  2. Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts,
  3. and the Massachusetts Institute of Technology, Cambridge, Massachusetts.
  4.  
  5.                         All Rights Reserved
  6.  
  7. Permission to use, copy, modify, and distribute this software and its 
  8. documentation for any purpose and without fee is hereby granted, 
  9. provided that the above copyright notice appear in all copies and that
  10. both that copyright notice and this permission notice appear in 
  11. supporting documentation, and that the names of Digital or MIT not be
  12. used in advertising or publicity pertaining to distribution of the
  13. software without specific, written prior permission.  
  14.  
  15. DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  16. ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  17. DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  18. ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  19. WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  20. ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  21. SOFTWARE.
  22.  
  23. ******************************************************************/
  24.  
  25. #include "X.h"
  26. #include "Xmd.h"
  27. #include "servermd.h"
  28.  
  29. #include "misc.h"
  30. #include "region.h"
  31. #include "gc.h"
  32. #include "windowstr.h"
  33. #include "pixmapstr.h"
  34. #include "scrnintstr.h"
  35.  
  36. #include "cfb.h"
  37. #include "cfbmskbits.h"
  38.  
  39. /* GetSpans -- for each span, gets bits from drawable starting at ppt[i]
  40.  * and continuing for pwidth[i] bits
  41.  * Each scanline returned will be server scanline padded, i.e., it will come
  42.  * out to an integral number of words.
  43.  */
  44. void
  45. cfbGetSpans(pDrawable, wMax, ppt, pwidth, nspans, pdstStart)
  46.     DrawablePtr        pDrawable;    /* drawable from which to get bits */
  47.     int            wMax;        /* largest value of all *pwidths */
  48.     register DDXPointPtr ppt;        /* points to start copying from */
  49.     int            *pwidth;    /* list of number of bits to copy */
  50.     int            nspans;        /* number of scanlines to copy */
  51.     unsigned int    *pdstStart;    /* where to put the bits */
  52. {
  53.     register unsigned int    *pdst;        /* where to put the bits */
  54.     register unsigned int    *psrc;        /* where to get the bits */
  55.     register unsigned int    tmpSrc;        /* scratch buffer for bits */
  56.     unsigned int        *psrcBase;    /* start of src bitmap */
  57.     int            widthSrc;    /* width of pixmap in bytes */
  58.     register DDXPointPtr pptLast;    /* one past last point to get */
  59.     int             xEnd;        /* last pixel to copy from */
  60.     register int    nstart; 
  61.     int             nend; 
  62.     int             srcStartOver; 
  63.     int             startmask, endmask, nlMiddle, nl, srcBit;
  64.     int            w;
  65.     unsigned int    *pdstNext;
  66.  
  67.     switch (pDrawable->depth) {
  68.     case 1:
  69.         mfbGetSpans(pDrawable, wMax, ppt, pwidth, nspans, pdstStart);
  70.         return;
  71.     case 8:
  72.         break;
  73.     default:
  74.         FatalError("cfbGetSpans: invalid depth\n");
  75.     }
  76.  
  77.     if (pDrawable->type == DRAWABLE_WINDOW)
  78.     {
  79.     psrcBase = (unsigned int *)
  80.         (((PixmapPtr)(pDrawable->pScreen->devPrivate))->devPrivate.ptr);
  81.     widthSrc = (int)
  82.            ((PixmapPtr)(pDrawable->pScreen->devPrivate))->devKind;
  83.     }
  84.     else
  85.     {
  86.     psrcBase = (unsigned int *)(((PixmapPtr)pDrawable)->devPrivate.ptr);
  87.     widthSrc = (int)(((PixmapPtr)pDrawable)->devKind);
  88.     }
  89.  
  90. #if PPW == 4
  91.     if ((nspans == 1) && (*pwidth == 1))
  92.     {
  93.     tmpSrc = *((unsigned char *)(psrcBase + (ppt->y * (widthSrc >> 2)))
  94.            + ppt->x);
  95. #if BITMAP_BIT_ORDER == MSBFirst
  96.     tmpSrc <<= 24;
  97. #endif
  98.     *pdstStart = tmpSrc;
  99.     return;
  100.     }
  101. #endif
  102.     pdst = pdstStart;
  103.     pptLast = ppt + nspans;
  104.     while(ppt < pptLast)
  105.     {
  106.     xEnd = min(ppt->x + *pwidth, widthSrc << (PWSH-2) );
  107.     psrc = psrcBase + (ppt->y * (widthSrc >> 2)) + (ppt->x >> PWSH); 
  108.     w = xEnd - ppt->x;
  109.     srcBit = ppt->x & PIM;
  110.     /* This shouldn't be needed */
  111.     pdstNext = pdst + PixmapWidthInPadUnits(w, PSZ);
  112.  
  113.     if (srcBit + w <= PPW) 
  114.     { 
  115.         getbits(psrc, srcBit, w, tmpSrc);
  116. /*XXX*/        putbits(tmpSrc, 0, w, pdst, -1); 
  117.         pdst++;
  118.     } 
  119.     else 
  120.     { 
  121.  
  122.         maskbits(ppt->x, w, startmask, endmask, nlMiddle);
  123.         if (startmask) 
  124.         nstart = PPW - srcBit; 
  125.         else 
  126.         nstart = 0; 
  127.         if (endmask) 
  128.         nend = xEnd & PIM; 
  129.         srcStartOver = srcBit + nstart > PLST;
  130.         if (startmask) 
  131.         { 
  132.         getbits(psrc, srcBit, nstart, tmpSrc);
  133. /*XXX*/        putbits(tmpSrc, 0, nstart, pdst, -1);
  134.         if(srcStartOver)
  135.             psrc++;
  136.         } 
  137.         nl = nlMiddle; 
  138.         while (nl--) 
  139.         { 
  140.         tmpSrc = *psrc;
  141. /*XXX*/        putbits(tmpSrc, nstart, PPW, pdst, -1);
  142.         psrc++;
  143.         pdst++;
  144.         } 
  145.         if (endmask) 
  146.         { 
  147.         getbits(psrc, 0, nend, tmpSrc);
  148. /*XXX*/        putbits(tmpSrc, nstart, nend, pdst, -1);
  149.         if(nstart + nend >= PPW)
  150.             pdst++;
  151.         } 
  152. #ifdef    notdef
  153.         pdst++; 
  154.         while(pdst < pdstNext)
  155.         {
  156.         *pdst++ = 0;
  157.         }
  158. #else
  159.         pdst = pdstNext;
  160. #endif
  161.     } 
  162.         ppt++;
  163.     pwidth++;
  164.     }
  165. }
  166.